package com.kristin.jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisClient {

    // 获取主库链接
    private static JedisPool jedisPool;

    private static JedisPool slavePool1;

    private static JedisPool slavePool2;

    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(8);
        config.setMaxTotal(18);
        jedisPool = new JedisPool(config, "82.156.194.234", 6379, 2000, "kristin");
        slavePool1 = new JedisPool(config, "82.156.194.234", 6380, 2000, "kristin");
        slavePool2 = new JedisPool(config, "82.156.194.234", 6380, 2000, "kristin");
    }

    public static Jedis getMasterJedis() {
        return jedisPool.getResource();
    }

    public static Jedis getSlaveJedis1() {
        return slavePool1.getResource();
    }

    public static Jedis getSlaveJedis2() {
        return slavePool2.getResource();
    }


    public static void main(String[] args) {
        for (int i = 50; i < 100; i++) {
            Jedis jedis = getMasterJedis();
//                System.out.println(jedis.del("key" + i , "value" + i));
//            System.out.println(jedis.get("key" + i));
            System.out.println(jedis.del("key" + i));

            jedis.close();
        }
    }

}
